import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_define.dart';
import 'package:xindong/manager/xindong_page_singleton.dart';
import 'package:xindong/models/xindong_task_class.dart';
import 'package:xindong/routes/user/task/xindong_daily_tasks_ctr.dart';
import 'package:xindong/routes/user/task/xindong_daily_tasks_item_widget.dart';
import 'package:xindong/widgets/common/xindong_app_bar.dart';
import 'package:xindong/widgets/container/xindong_empty_container.dart';
import 'package:xindong/widgets/container/xindong_fenzu_container.dart';

class XinDongDailyTasksYeMian extends StatelessWidget {
  const XinDongDailyTasksYeMian({super.key});

  void _onTap(XinDongTaskClass model) {
    XinDongPageSingleton.instance.jumpWithName(model.name ?? "", onlyToAuthYeMian: true);
  }

  @override
  Widget build(BuildContext context) {
    final _controller = Get.put(XinDongDailyTasksCtr());
    return Scaffold(
      appBar: XinDongAppBar("每日任务"),
      body: GetBuilder<XinDongDailyTasksCtr>(builder: (controller) {
        return XinDongEmptyContainer(
          dataList: controller.dataList,
          child: XinDongGroupSectionContainer(
            dataList: controller.dataList,
            sectionHeaderBuilder: (BuildContext context, int index) {
              List<XinDongTaskClass> sectionList = controller.dataList![index];
              if (sectionList.isEmpty) {
                return const SizedBox();
              }
              return Container(
                height: 36,
                alignment: Alignment.centerLeft,
                padding: const EdgeInsets.only(left: kPaddingValue),
                child: Text(
                  sectionList.first.types == 1 ? '新手任务' : '日常任务',
                  style: const TextStyle(color: DZColors.titleColor, fontSize: 15, height: 1.2),
                ),
              );
            },
            separatorBuilder: (BuildContext context, int index) {
              return const SizedBox();
            },
            itemBuilder: (BuildContext context, int section, int index, data) {
              return XinDongDailyTasksItemWidget(model: data, onTap: _onTap);
            },
          ),
        );
      }),
    );
  }
}
